import fileApi from '../api/file-api'

/**
 * 富文本编辑器默认配置
 *
 */
export const tinymceConfig = {
	height: '100%',
	min_height: 500,
	// 右下角品牌信息
	branding: false,
	// 右上角推广信息
	promotion: false,
	language: 'zh-Hans',
	base_url: '/tinymce',
	plugins: [
		'preview',
		'powerpaste',
		'importcss',
		'searchreplace',
		'autolink',
		'autosave',
		'save',
		'directionality',
		'code',
		'visualblocks',
		'visualchars',
		'fullscreen',
		'image',
		'link',
		'media',
		'template',
		'codesample',
		'table',
		'charmap',
		'pagebreak',
		'nonbreaking',
		'anchor',
		'insertdatetime',
		'advlist',
		'lists',
		'wordcount',
		'help',
		'charmap',
		'quickbars',
		'emoticons'
	].join(' '),
	toolbar: [
		'undo redo bold italic underline strikethrough forecolor backcolor removeformat',
		'fontfamily fontsize blocks',
		'alignleft aligncenter alignright alignjustify outdent indent numlist bullist',
		'pagebreak charmap emoticons insertfile image media link anchor codesample fullscreen preview print'
	].join(' | '),
	quickbars_insert_toolbar: '',
	pagebreak_separator: '<div style="page-break-after: always;"></div>',
	quickbars_selection_toolbar: [
		'bold italic underline strikethrough',
		'fontfamily fontsize',
		'alignleft aligncenter alignright alignjustify',
		'forecolor backcolor'
	].join(' | '),
	toolbar_sticky: true,
	toolbar_mode: 'wrap',
	font_size_formats: new Array(101)
		.fill(0)
		.map((v, i) => i + 10 + 'px')
		.join(' '),
	font_family_formats: [
		'微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif',
		'苹果苹方=PingFang SC,Microsoft YaHei,sans-serif',
		'宋体=simsun,serif',
		'仿宋=FangSong,serif',
		'黑体=SimHei,sans-serif',
		'Arial=arial,helvetica,sans-serif',
		'Arial Black=arial black,avant garde',
		'Book Antiqua=book antiqua,palatino',
		'Comic Sans MS=comic sans ms,sans-serif',
		'Courier New=courier new,courier',
		'Georgia=georgia,palatino',
		'Helvetica=helvetica',
		'Impact=impact,chicago',
		'Symbol=symbol',
		'Tahoma=tahoma,arial,helvetica,sans-serif',
		'Terminal=terminal,monaco',
		'Times New Roman=times new roman,times',
		'Verdana=verdana,geneva',
		'Webdings=webdings',
		'Wingdings=wingdings,zapf dingbats'
	].join(';'),
	images_upload_handler(blobInfo: any) {
		const formData = new FormData()
		formData.append('files', blobInfo.blob())

		return new Promise(resolve => {
			fileApi.uploadImage(formData).then(({data}) => {
				resolve(data.url)
			})
		})
	}
}
